﻿/*
=======================================================
    MagnetHead【磁头】
=======================================================
*/

namespace Services
{
    public interface IMagnetHeadRepository : IRepository<MagnetHead>
    {
    }


    public class MagnetHeadRepository : BaseRepository<MagnetHead>, IMagnetHeadRepository
    {
        public MagnetHeadRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<MagnetHead> query)
            : base(dB, currentUser, query)
        {
        }
        
        public override int Insert(MagnetHead entity)
        {
            var groupInfoID = _currentUser.CurrentUserInfo.LoginTypeID;
            var exists = _DB.Queryable<MagnetHead>()
                            .Where(m => m.GroupInfoID == groupInfoID && m.DeviceID == entity.DeviceID)
                            .Any();
            if (exists)
            {
                throw new CustomException("存在相同的 GroupInfoID 和 DeviceID 组合，不能插入！");
            }
            return base.Insert(entity);
        }
    }
}
